<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/

namespace Post\Controller;
class DownloadController extends \Member\Controller\IndexController {

	//下载文件
	public function fileAction(){
		
		$id=intval($_GET['id']);
		if($id>0){
			$file=M('File')->where(" fid=$id")->find();
			if(!empty($file['fid'])){
				@header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
				@header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
				@header('Cache-Control: max-age=31536000'); 
				@header('Content-Encoding: none');          
				@header('Content-Type: '.$file['filetype'].'');          
				@header('Content-Disposition: attachment; filename="'.$file['filename'].'"');  
				@header('Pragma: no-cache');           
				@header('Expires: 0');
				
				$fd = fopen(FOXPHP_PATH.'/'.$file['filepath'], "rb");         
				print @fread($fd, filesize(FOXPHP_PATH.'/'.$file['filepath']));
				flush();  
				fclose($fd);	
			}else{
				$this->error('文件不存在!','/');
			}
		}else{
			$this->error('文件不存在!','/');
		}

	}

}